import { sys } from "cc";

/**本地存数据的key*/
export enum ITEM_STORAGE {
    LANGUAGE = "language",
    SOUND_ENABLED = "sound_enabled",//音效是否开启
    MUSIC_ENABLED = "music_enabled",//背景音乐是否开启
    VIBRATION_ENABLED = "vibration_enabled",//震动是否开启
    BET_CHIP_ID = "bet_chip_id",//用户选择的下注id
}
export  class LocalStorageMgr{
        private static _instance:LocalStorageMgr;
        private readonly _keys_1:Array<ITEM_STORAGE> = [];//退出账号需要清理的缓存
        public static get instance():LocalStorageMgr{
            if(this._instance==null)
            {
                this._instance = new LocalStorageMgr();
            }
            return this._instance;
        }
        getItem(key:ITEM_STORAGE):any {
            return sys.localStorage(key);
        }
        setItem(key:ITEM_STORAGE,value:String){
            sys.localStorage.setItem(key,value);
        }
        removeLocalStorageItem(key:ITEM_STORAGE) {
            sys.localStorage.removeItem(key);
        }
        /**
         * 批量清除缓存
         * @param keys 需要保留的缓存项
         */
         clearWithoutKeys(keys:ITEM_STORAGE[]) {
        for (const key in ITEM_STORAGE) {
            if (keys.indexOf(ITEM_STORAGE[key]) === -1){
                sys.localStorage.removeItem(ITEM_STORAGE[key]);
            }              
        }
    }
}